/**
 *  1. 拿到：图片上传之后的地址
 *  2. 拿到form表单的数据
 *
 *  合并成一个对象。一起提交给后台
 *
 *  图片上传的时候，把数据传递给vuex;
 *  点击确定按钮才提交数据
 *
 */
import { uploadFile, actionUploadFile } from '@/api/modules/upload'
const table = {
  namespaced: true,
  state: {
    submit: false,
    opt: {
    },
    file: {}
  },
  mutations: {
    SET_SUBMIT(state, status) {
      state.submit = status;
    },
    SET_UPLOAD_FILE(state, file) {

    },
    // 对于图片上传接口的参数
    SET_FILE(state, file) {
      state.file = file
    }
  },
  actions: {
    updateUploadFile({ commit, state }) {
      return new Promise((resolve, reject) => {
        uploadFile(state.file.raw).then(result => {
          console.log('result: 上传成工之后的数据:', result)
          commit('SET_UPLOAD_FILE', result)
          resolve()
        })
      })
    },
    // 上传函数
    updateActionUpload({ commit, state }, data) {
      return new Promise((resolve, reject) => {
        actionUploadFile(state.file).then(result => {
          console.log('result: 上传成-------：之后的数据:', result)
          commit('SET_UPLOAD_FILE', result)
          resolve()
        })
      })
    },
    getUploadFile({ commit }, data) {
      console.log('data:', data)
      commit('SET_FILE', data)
    }
  }
}

export { table }
